<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Gallery extends MY_Controller {

    public function __construct()
    {
        parent::__construct();
        }

    /**
     * Default function
     */
    public function index($id = false,$alias=false,$post_id=false)
    {
        
        if(!$id || !$alias) show_404();
       
        if(!$post_id){
            $posts = _get_posts($id);
            if(!empty($posts)){
           
            $alias = $this->_global->_unserialize($posts[0]->seo_alias);
            $alias = $alias[$this->session->userdata('lan')]['alias'];
            redirect('gallery/c'.$id.'/'.$alias.'-'.$posts[0]->post_id);
            }
            else show_404();
        }
        else{
            $posts = _get_posts($id,$post_id);
            $a = $this->_global->_unserialize($posts->seo_alias);
            if($a[$this->session->userdata('lan')]['alias']!=$alias) 
               show_404();
        }
        if(!empty($posts)){
            $this->load->model('categories');
            if($id && $post_id===false)
            {
                $category = $this->categories->getCat(array('cat_id'=>$id));
                $a = $this->_global->_unserialize($category->cat_alias);
                if($a[$this->session->userdata('lan')]['alias']!=$alias) show_404();
                $this->assign('category',$category);
            }
            $this->assign('posts',$posts); 
            $this->assign('cat_id',$id); 
            $this->assign('post_id',$post_id);
            $this->assign('alias',$alias); 
        }
        else show_404();
    }
    
    
    
}